<?php
/**
 *
 * @author Duminda Dharmakeerthi
 *
 */
class user{
	private $userId;
	private $userName;
	private $userPassword;
	private $userFullName;
	private $userCreatedDate;
	private $userRoleId;
	private $userAddress;
	private $userLandPhone;
	private $userMobilePhone;
	private $userEmail;
	private $userFax;
	
	function __construct(){
	}
	
	/**
	 * Fill the user information to user object
	 * 
	 * @param $userName
	 * @param $userPassword
	 * @param $userFullName
	 * @param $userRoleId
	 * @param $userAddress
	 * @param $userLandPhone
	 * @param $userMobilePhone
	 * @param $userEmail
	 * @param $userFax
	 * @return User object with the given user information
	 */
	public static function fillUser($userName, $userPassword, $userFullName, $userRoleId, $userAddress, $userLandPhone, $userMobilePhone, $userEmail, $userFax){
		$U = new self();
		$U->setUser($userName, $userPassword, $userFullName, $userRoleId, $userAddress, $userLandPhone, $userMobilePhone, $userEmail, $userFax);
		return $U;
	}
	
	/**
	 * Set the User values
	 * 
	 * @param $userName
	 * @param $userPassword
	 * @param $userFullName
	 * @param $userRoleId
	 * @param $userAddress
	 * @param $userLandPhone
	 * @param $userMobilePhone
	 * @param $userEmail
	 * @param $userFax
	 */
	protected function setUser($userName, $userPassword, $userFullName, $userRoleId, $userAddress, $userLandPhone, $userMobilePhone, $userEmail, $userFax){
		$this->userName = $userName;
		$this->userPassword = $userPassword;
		$this->userFullName = $userFullName;
		$this->userRoleId = $userRoleId;
		$this->userAddress = $userAddress;
		$this->userLandPhone = $userLandPhone;
		$this->userMobilePhone = $userMobilePhone;
		$this->userEmail = $userEmail;
		$this->userFax = $userFax;
	}
	
	public function addUser(){
		$today = date('Y-m-d');
		$addUserQuery = "INSERT INTO users (
							userName,
							userPassword,
							userFullName,
							userCreatedDate,
							userRoleId,
							userAddress,
							userLandPhone,
							userMobilePhone,
							userEmail,
							userFax
						) VALUES(
							'$this->userName',
							'$this->userPassword',
							'$this->userFullName',
							'$today',
							'$this->userRoleId',
							'$this->userAddress',
							'$this->userLandPhone',
							'$this->userMobilePhone',
							'$this->userEmail',
							'$this->userFax'
						)";
		if(mysql_query($addUserQuery)){
			return mysql_insert_id();
		}else{
			return 0;
		}
	}
}
?>